/**
 * 删除问题
 */
import query from '../../untils/mysql';
import { Tip } from '../../untils/untils';
import { check, validationResult } from 'express-validator';

const validator = [
    check('id').notEmpty().withMessage("问题Id不能为空！"),
]
const POST = async (req: any, res: any, next: any) => {
    try {
        const { id } = req.body;
        var errors = validationResult(req);
        if (!errors.isEmpty()) {
            return Tip.tipError(res, errors.array()[0].msg);
        }
        await query(`delete from problem where id = '${id}'`);
        return Tip.tipSuccess(res, '删除成功')
    } catch (error: any) {
        Tip.tipError500(res, error)
    }
}

export {
    POST,
    validator
}